package lab03.test04;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test {
    //编写一段程序来完成文件拷贝的工作。
    // 首先在D盘下创建文件夹source和target，
    // 然后在source文件夹中存放“High.mp3”，使用字节输入流读入文件，
    // 使用字节输出流写入文件夹target下。
    public static void main(String[] args) {
        String source = "D:\\旅院\\作业\\java\\source\\01. Stay With Me.mp3";
        String target = "D:\\旅院\\作业\\java\\target";

        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream(source);
            fileOutputStream = new FileOutputStream(target);

            int data;

            while ((data = fileInputStream.read()) != 1) {
                //fileInputStream.read();
                fileOutputStream.write(data);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
